package group

import (
	"context"

	"gitee.com/gao-deguang/easy-chat/apps/social/api/internal/svc"
	"gitee.com/gao-deguang/easy-chat/apps/social/api/internal/types"
	"gitee.com/gao-deguang/easy-chat/apps/social/rpc/social"
	"gitee.com/gao-deguang/easy-chat/pkg/ctxdata"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type GroupListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 用户群组列表
func NewGroupListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GroupListLogic {
	return &GroupListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GroupListLogic) GroupList(req *types.GroupListReq) (resp *types.GroupListResp, err error) {
	// todo: add your logic here and delete this line
	lists, err := l.svcCtx.Social.GroupList(l.ctx, &social.GroupListReq{
		UserId: ctxdata.GetUID(l.ctx),
	})
	if err != nil {
		return &types.GroupListResp{}, nil
	}
	var list []*types.Groups
	copier.Copy(&list, &lists.List)
	return &types.GroupListResp{List: list}, nil
}
